import { Model } from './model.js';
var model = new Model();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    current: 1,
    current_scroll: 1,
    item_current: 0,
    interval: 2000,
    duration: 500,
    order_list: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  onShow: function () {
    this.getUserStore();
  },
  // head_tab 切换
  handleChange: function (e) {
    var head_tab_curr = parseInt(e.detail.key) - 1;
    this.setData({ item_current: head_tab_curr })
  },

  // 切换tab
  switchTab: function (e) {
    var tab_curr = e.detail.current;
    this.setData({ current: tab_curr + 1 });
  },

  // 获取我的收藏
  getUserStore() {
    model.getUserStore((res) => {
      this.list = res.data.data
      this.setData({ list: res.data.data })
    })
  },

  // 删除收藏
  deleteStore(e){
    var id= e.currentTarget.dataset.id;
    wx.showModal({
      title: '删除收藏',
      content: '确定要删除这条收藏吗？',
      showCancel: true,
      cancelText: '取消',
      cancelColor: '#000000',
      confirmText: '确定',
      confirmColor: '#c80212',
      success: (result) => {
        if(result.confirm){
          model.deleteStore(id,(res)=>{
            this.getUserStore()
            wx.showToast({
              title: res.data.msg,
              icon: 'success'
            });
          })
        }
      }
    });
  }
})